#include <iostream>
//#include "MyString.h"
using namespace std;

class Goods {
public:
	Goods(int w) {
		weight = w;
		total_weight += w;
	}
	~Goods() {
		total_weight -= weight;
	}
	int Weight() {
		return weight;
	}
	static int TotalWeight() {
		return total_weight;
	}
	Goods* next;
private:
	int weight;
	static int total_weight;
};
int Goods::total_weight = 0;

void purchase(Goods* &f, Goods*& r, int w) {
	Goods *p = new Goods(w);
	p->next = NULL;
	if (f == NULL) {
		f = r = p;
		//cout << f <<endl<< r <<endl<< p << endl;
	}
	else {
		r->next = p;
		r = r->next;
		cout << r<<endl;
		cout << f << endl;
	}
};
void sale(Goods*& f,Goods*& r) {
	if (f == NULL) {
		cout << "No any goods!\n";
		return;
	}
	Goods*q = f;
	f = f->next;
	delete q;
	cout << "saled.\n";
}
void main() {
	Goods* front = NULL,* rear=NULL;
	int w;
	int choice;
	do {
		cout << "Please choice:\n";
		cout << "key in 1 is purchase,\n key in 2 is sale,\n key in 0 is over,\n";
		cin >> choice;
		switch (choice)
		{
			case 1:
				{
					cout << "Input weight:";
					cin >> w;
					purchase(front, rear, w);
					break;
				}
			case 2:
			{
				sale(front, rear);
				break;
			}
			case 0:
				break;
		}
		cout << "Now total weight is:" << Goods::TotalWeight() << endl;
	} while (choice);

}